'use strict';

/**
 * @ngdoc function
 * @name sfhtHaitaoCmsApp.controller:MainCtrl
 * @description
 * # MainCtrl
 * Controller of the sfhtHaitaoCmsApp
 */
angular.module('sfhtHaitaoCmsApp')
  .controller('LoginCtrl', function($scope, $injector, $location, CONST_PASSWORD_SLOT, CONST_INDEX_LINK, store) {
    var url = $location.absUrl();
    $scope.options = {
      sectionsColor: ['#1bbc9b', '#4BBFC3', '#7BAABE'],
      navigation: false,
      navigationPosition: 'right',
      scrollingSpeed: 1000
    }

    $scope.login = function() {
      var userService = $injector.get("UserService");
      userService.logout()
        .then(function(data) {
          store.remove('csrfToken');
          store.remove("userId");
          store.remove("profile");
          userService.login({
            accountId: $scope.account,
            // type: /^1\d{10}$/.test($scope.account) == true ? 'MOBILE' : 'MAIL',
            password: faultylabs.MD5($scope.password + CONST_PASSWORD_SLOT).toLowerCase()
          })
            .then(function(data) {
              store.set("userId", data.userId);
              window.location.href = CONST_INDEX_LINK;
            }, function(data) {
              alert(data);
            });
        }, function(data) {
          alert(data);
        });
    }
  });